//到货通知单
$(function(){
	//搜索
	$('.searchBar').click(function(){
		var thisform=$(this).parent('form');
		var order_no=thisform.find('input[name=order_no]').val();
		var mailNo=thisform.find('input[name=mailNo]').val();
		var receiveMan=thisform.find('input[name=receiveMan]').val();
		var print_status=thisform.find('input[name=print_status]').val();
		var start_time=thisform.find('input[name=start_time]').val();
		var end_time=thisform.find('input[name=end_time]').val();
		var ems_name=thisform.find('input[name=ems_name]').val();
		var has_weight=thisform.find('input[name=has_weight]').val();
		var goods_name=thisform.find('input[name=goods_name]').val();
		var nums=thisform.find('input[name=nums]').val();
		var check_cate=thisform.find('input[name=check_cate]').val();
		var merchant_code=thisform.find('input[name=merchant_code]').val();
		$('#printorderGreenDatagrid').datagrid('options').pageNumber=1;//设置页码初始值为1
		$('#printorderGreenDatagrid').datagrid({ 
			queryParams:{
				order_no:order_no,
				mailNo:mailNo,
				receiveMan:receiveMan,
				start_time:start_time,
				end_time:end_time,
				print_status:print_status,
				goods_name:goods_name,
				ems_name:ems_name,
				nums:nums,
				check_cate:check_cate,
				has_weight:has_weight,
				merchant_code:merchant_code
			}
		});
	})
	
	$('.AdvanceSearch').click(function(){
		$('#printAdvanceSearch').toggle(100);
	})

	$('#printorderGreenDatagrid').datagrid({
		//url:getprintorderGreenUrl+"?randnum="+Math.floor(Math.random()*1000000),
		url:getprintorderGreenUrl,
		title:'快递公司费用',
		fitColumns:true,
		rownumbers:true,
		pageSize:25,
		pageNumber:1,
		pageList:[5,10,15,20,25,30,40,50],
		columns:[[
		{field:'id',title:'id',checkbox:true},
		{field:'order_no',title:'订单编号',sortable:true},
		{field:'logistics_no',title:'电子面单号',sortable:true},
		{field:'user_name',title:'收件人姓名',sortable:true},
		{field:'user_phone',title:'收件人电话',sortable:true},
		{field:'province',title:'省',sortable:true},
		{field:'city',title:'市',sortable:true},
		{field:'area',title:'区',sortable:true},
		{field:'user_address',title:'收件人地址',sortable:true},
		{field:'ems_fee',title:'快递费用',sortable:true},
		{field:'ems_fee_rate',title:'客户快递费用',sortable:true},
		{field:'logiscompany_name',title:'快递公司',sortable:true},
		{field:'has_weight',title:'已称重',sortable:true},
		{field:'add_time',title:'推送时间',sortable:true}
		]],
		onLoadError:function(data){
			var info=eval('('+data.responseText+')');
			$.messager.confirm('错误提示',info.message,function(r){
				var tab=$('#Tabs').tabs('getSelected');
				var index=$('#Tabs').tabs('getTabIndex',tab);
				$('#Tabs').tabs('close',index);
			});
		},
		rowStyler:function(index,row){
			if (row.color==0){
				return 'background-color:pink;color:blue;font-weight:bold;';
			}
		},
		pagination:true,
		fit:true,
		showFooter: true,
	});
});
printorderGreenObj={
	showAll:function(){//显示默认条件下所有数据
		$('#printorderGreenDatagrid').datagrid({ queryParams:''});
	},
	showAdvanceBar:function(){
		$('#printorderGreenDatagrid').datagrid({ queryParams:{show_advance:1}});
	},
	save:function(url){//编辑后保存数据
		$('#booksInfoEditForm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
            	 var result=eval('('+result+')');
                if (!result.status){
                    $.messager.confirm('错误提示',result.message,function(r){
                    	$('#booksInfoEditDialog').dialog('close');
                    });
                }else{
                    $('#booksInfoEditDialog').dialog('close');      
                    $('#printorderGreenDatagrid').datagrid('reload');    
                }
            }
        });
	},
	editBar:function(){//显示编辑框
		var booksInfoRow=$('#printorderGreenDatagrid').datagrid('getSelections');
        if (booksInfoRow.length>1){		            	
            $.messager.alert('提示','一次只能修改一条记录!','info');
        }else if(booksInfoRow.length==1){            	
        	$('#booksInfoEditDialog').dialog('open').dialog('setTitle','编辑');
            $('#booksInfoEditForm').form('load',booksInfoRow[0]);
        }else{
			$.messager.alert('推送提示','请选择列表数据','error');
		}
	},
	excelBar:function(){//导出excel
		var thisform=$('#printorderGreenSearchForm');
		var order_no=thisform.find('input[name=order_no]').val();
		var mailNo=thisform.find('input[name=mailNo]').val();
		var receiveMan=thisform.find('input[name=receiveMan]').val();
		var start_time=thisform.find('input[name=start_time]').val();
		var end_time=thisform.find('input[name=end_time]').val();
		var ems_name=thisform.find('input[name=ems_name]').val();
		var has_weight=thisform.find('input[name=has_weight]').val();
		// console.log(order_no);
		url=getprintorderGreenUrl+"&excel=1&rows=6000";
		if(order_no!=''){
			url=url+"&order_no="+order_no;
		}
		if(mailNo!=''){
			url=url+"&mailNo="+mailNo;
		}
		if(ems_name!=''){
			url=url+"&ems_name="+ems_name;
		}
		if(has_weight!=''){
			url=url+"&has_weight="+has_weight;
		}
		if(receiveMan!=''){
			url=url+"&receiveMan="+receiveMan;
		}
		if(start_time!=0){
			url=url+"&start_time="+start_time;
		}
		if(end_time!=0){
			url=url+"&end_time="+end_time;
		}
		window.location.href=url;
	},
	reloadBar:function(){//刷新数据
		$('#printorderGreenDatagrid').datagrid('reload');
	}
}